package com.msy.mai.module.system.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.msy.mai.common.core.utils.StringUtils;
import com.msy.mai.module.system.entity.domain.SysRole;
import com.msy.mai.module.system.entity.vo.SysRoleVo;
import com.msy.mai.module.system.mapper.SysRoleMapper;
import com.msy.mai.module.system.service.SysRoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* @author Wang
* @description 针对表【sys_role(角色信息表)】的数据库操作Service实现
* @createDate 2024-10-27 19:20:41
*/
@Service
@RequiredArgsConstructor
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole>
    implements SysRoleService {

    private final SysRoleMapper sysRoleMapper;

    @Override
    public Set<String> selectRolePermissionByUserId(Long userId) {
        List<SysRoleVo> perms = this.selectRolesByUserId(userId);
        Set<String> permsSet = new HashSet<>();
        for (SysRoleVo perm : perms) {
            if (ObjectUtil.isNotNull(perm)) {
                permsSet.addAll(StringUtils.splitList(perm.getRoleKey().trim(),":"));
            }
        }
        return permsSet;
    }

    @Override
    public List<SysRoleVo> selectRolesByUserId(Long userId) {
        return sysRoleMapper.selectRolesByUserId(userId);
    }
}




